package com.tbynet.jwp.portal;

import com.jfinal.aop.Inject;
import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.tbynet.jwp.framework.core.JwpInterceptor;
import com.tbynet.jwp.service.spi.UserManager;
import com.tbynet.jwp.model.Users;

public class PortalInterceptor extends JwpInterceptor implements Interceptor {
	
	@Inject
    UserManager userManager;

	@Override
	public void intercept(Invocation inv) {
		PortalController ctr = (PortalController) inv.getController();
		
		Users user = null;
		String sessionId = ctr.getCookie(Users.sessionIdName);
		if (null != sessionId) {
			user = userManager.validateAndGetLoginUser(sessionId);
		}
		
		if(null != user) {
			// 用户登录
			ctr.set(Users.loginUserCacheName, user);
		}
		
		ctr.set("ACTION_KEY", inv.getActionKey());
		
		inv.invoke();
	}

}
